﻿using System;
using WickedFlame.Core.Shapes;
using System.Windows;
using System.Windows.Input;

namespace WickedFlame.Core.Tools
{
    /// <summary>
    /// Factory base class for tools that create vecshapes
    /// Lets subclasses create individual shapes and adds them to the shapecontent of the drawing canvas
    /// Based on the AbstractFactory Pattern
    /// </summary>
    public abstract class FactoryTool : VectorTool
    {
        public FactoryTool()
            : base()
        {
        }

        /// <summary>
        /// unselect all shapes when a shape tool is selected
        /// </summary>
        /// <param name="canvas"></param>
        public override void OnActivate(DrawingCanvas canvas)
        {
            canvas.SelectedLayer.UnselectAll();
        }

        /// <summary>
        /// Catches the click event and calls CreateShape(Point mousePosition)
        /// Adds the VECShape to the canvas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnMouseLeftButtonDown(DrawingCanvas sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            sender.AddShape(CreateShape(Mouse.GetPosition(sender)));
        }

        /// <summary>
        /// Factory Method that returnes a concrete vecshape.
        /// Lets subclasses create individual concrete vecshapes
        /// </summary>
        /// <returns></returns>
        protected abstract VectorShape CreateShape(Point mousePosition);
    }
}
